package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/metadata"
	"grpc_starter/grpc_meta/pb/pb"
	"net"
)

const (
	protocol = "tcp"
	address  = "127.0.0.1:5001"
)

type server struct {
}

func (s *server) SayHello(ctx context.Context, reqData *pb.ReqData) (*pb.ResData, error) {
	if md, ok := metadata.FromIncomingContext(ctx); ok {
		fmt.Println("message: ", md["message"])
	}
	return &pb.ResData{Data: "hello " + reqData.Message}, nil
}

func main() {

	listen, _ := net.Listen(protocol, address)

	s := grpc.NewServer()

	pb.RegisterGreetServer(s, new(server))

	_ = s.Serve(listen)

}
